 var table ,form ,laypage ,layer ,element ,laydate ,upload;//时间组件
//获取用户信息
var thistr;//
//多选，单选
var pageDataIdMap;
var idMap = new Map();
var newidMap = new Map();//当前选择的列表
$(function(){
	var saveurl="";
	layui.use(['table','form','laypage','layer', 'element', 'laydate','upload'], function(){
        table = layui.table;
        form=layui.form;
        laypage = layui.laypage ;//分页
        layer = layui.layer ;//弹层
        element = layui.element; //元素操作
        laydate = layui.laydate; //时间组件 
        upload = layui.upload;
        dictPublicfun()
        var typedata={"condition":[{"field":"isBlackList","keyword":"1"}]};
		//监听表格数据	   
		table.render({
		    elem: '#tabledata',
		    height: $(window).height()-200,		   
		    text: {
			    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
			  },
			method: 'post',  
			loading: true,
		    url: '/scmsUser/getList.do' ,//数据接口
		    where:{"reqData":JSON.stringify(typedata)},
		    headers: setHeader(),
		    parseData: function(res){
                return res.resultData;
            },
            response: {
                statusName: 'status', //规定数据状态的字段名称，默认：code
                statusCode: 200, //规定成功的状态码，默认：0
                msgName: 'hint', //规定状态信息的字段名称，默认：msg
                countName: 'total', //规定数据总数的字段名称，默认：count
                dataName: 'data' //规定数据列表的字段名称，默认：data
            },
		    page: true, //开启分页
		    cols: [[    //表头
		      {field: 'id', title: 'ID',   align:'center',hide:true,width:5},
		      {field: 'xuhao', title: '序号',  align:'center', type:'numbers',width:50,fixed:'left'},
		      {field: '', title: '头像', align:'left',width:120,
		    	  templet: function(data){
		    		  if(data.image==null||data.image==""){
		    			  return ""
		    		  }else{
			    		  return "<a class='lookurladdress' lay-event='lookimgtx' title='图片查看'   href='javascript:void(0);'>"+
				    		        "<ul id='img_"+data.image+"'>"+
										"<li><img data-original='"+data.imageZh+"' src='"+data.imageZh+"' style='width:100%;height:100%'/></li>"+
									 "</ul>"+
								 "</a>" 
		    		  }			 
					form.render();//需要渲染一下
		    	  }
		       },
		      {field: 'userName', title: '用户名称', align:'left',width:180},
		      {field: 'card', title: '身份证号码', align:'left',width:150},
		      {field: 'name', title: '姓名', align:'left',width:150},
		      {field: 'phone', title: '手机号', align:'left',width:150},
		      {field: 'typeZh', title: '类型', align:'left',width:150},
		      {field: 'companyName', title: '单位', align:'left',width:150},
		      {field: '', title: '身份证正面照', align:'left',width:200,
		    	  templet: function(data){
		    		  if(data.cardJustImage==null||data.cardJustImage==""){
		    			  return ""
		    		  }else{
		            	   return "<a class='lookurladdress' lay-event='lookimg' title='图片查看'   href='javascript:void(0);'>"+
				    		        "<ul id='img_"+data.cardJustImage+"'>"+
										"<li><img data-original='"+data.cardJustImageZh+"' src='"+data.cardJustImageZh+"'  alt='图片'  style='width:100%;height:100%'/></li>"+
									 "</ul>"+
								   "</a>"
		    		  }				 
		              form.render();//需要渲染一下
		           }  
		      },
		      {field: '', title: '身份证反面照', align:'left',width:200,
		    	  templet: function(data){
		    		  if(data.cardBackImage==null||data.cardBackImage==""){
		    			  return ""
		    		  }else{
		            	   return "<a class='lookurladdress' lay-event='lookimg2' title='图片查看'   href='javascript:void(0);'>"+
				    		        "<ul id='img_"+data.cardBackImage+"'>"+
										"<li><img data-original='"+data.cardBackImageZh+"' src='"+data.cardBackImageZh+"'  alt='图片'  style='width:100%;height:100%'/></li>"+
									 "</ul>"+
								   "</a>" 
		    		  }				 
		              form.render();//需要渲染一下
		           }  
		      },
		      {field: '', title: '创建时间', align:'center',width:150, 
		    	  templet: function(data){
			  			return changeTime(data.createTime)					        							        
			  		}  
		      },
		      {field: '', title: '操作', align:'center',width:180,fixed:'right',
			      templet: function(data){
						return '<div class="layui-btn-group">'+	  
	                             '<a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs BTNSHOW BTNSHOW_DELETE" lay-event="del" >移除黑名单</a>'+	                             
                               '</div>'   
					}
		      }
		    ]],
		    done: function (res) {
		    	 permissionFUN()//功能按钮权限
		    	 if(res.status!=200){
		    		if(res.status == 666){
		    			  TIMEOUT(); 
	  		        }else{
                	  $(".layui-none").text(res.resultMsg)
	  		        }  
                }
            }
		});
      $("#addbtn").click(function(){
    	  layer.open({
     	        type: 1,
		        area: ['100%', '100%'],
		        fix: false, //不固定
		        maxmin: true,
		        shadeClose: true,
		        shade:0.4, //遮罩层
		        title: ['选择黑名单','background:#1E9FFF;color:#fff'],
		        content: $('#form_addDaa')
		    });
  		//监听表格数据
    	var formreqData2={"condition":[{"field":"isBlackList","keyword":"0"}]} 
  		table.render({
  		    elem: '#scmsCompanyData',
  		    height: $(window).height()-200,		   
  		    text: {
  			    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
  			  },			
  			method: 'post',  
  			loading: true,
  		    url: '/scmsUser/getList.do' ,//数据接口
  		    where:{"reqData" : JSON.stringify(formreqData2)},
  		    headers: setHeader(),
  		    parseData: function(res){  		     
                  return res.resultData;                  
              },
           response: {
              statusName: 'status', //规定数据状态的字段名称，默认：code
              statusCode: 200, //规定成功的状态码，默认：0
              msgName: 'hint', //规定状态信息的字段名称，默认：msg
              countName: 'total', //规定数据总数的字段名称，默认：count
              dataName: 'data' //规定数据列表的字段名称，默认：data
           },
  		    page: true, //开启分页
  		    cols: [[    //表头	 
  		      {type: 'checkbox', fixed: 'left'},	
  		      {field: 'id', title: 'ID',   align:'center',hide:true,width:5},
		      {field: 'xuhao', title: '序号',  align:'center', type:'numbers',width:50,fixed:'left'},
		      {field: '', title: '头像', align:'left',width:120,
		    	  templet: function(data){
		    		  if(data.image==null||data.image==""){
		    			  return ""
		    		  }else{
			    		  return "<a class='lookurladdress' lay-event='lookimgtx' title='图片查看'   href='javascript:void(0);'>"+
				    		        "<ul id='img_"+data.image+"'>"+
										"<li><img data-original='"+data.imageZh+"' src='"+data.imageZh+"' style='width:100%;height:100%'/></li>"+
									 "</ul>"+
								 "</a>" 
		    		  }			 
					form.render();//需要渲染一下
		    	  }
		       },
		      {field: 'userName', title: '用户名称', align:'left',width:180},
		      {field: 'card', title: '身份证号码', align:'left',width:150},
		      {field: 'name', title: '姓名', align:'left',width:150},
		      {field: 'phone', title: '手机号', align:'left',width:150},
		      {field: 'typeZh', title: '类型', align:'left',width:150},
		      {field: 'companyName', title: '单位', align:'left',width:150},
		      {field: '', title: '身份证正面照', align:'left',width:200,
		    	  templet: function(data){
		    		  if(data.cardJustImage==null||data.cardJustImage==""){
		    			  return ""
		    		  }else{
		            	   return "<a class='lookurladdress' lay-event='lookimg' title='图片查看'   href='javascript:void(0);'>"+
				    		        "<ul id='img_"+data.cardJustImage+"'>"+
										"<li><img data-original='"+data.cardJustImageZh+"' src='"+data.cardJustImageZh+"'  alt='图片'  style='width:100%;height:100%'/></li>"+
									 "</ul>"+
								   "</a>"
		    		  }				 
		              form.render();//需要渲染一下
		           }  
		      },
		      {field: '', title: '身份证反面照', align:'left',width:200,
		    	  templet: function(data){
		    		  if(data.cardBackImage==null||data.cardBackImage==""){
		    			  return ""
		    		  }else{
		            	   return "<a class='lookurladdress' lay-event='lookimg2' title='图片查看'   href='javascript:void(0);'>"+
				    		        "<ul id='img_"+data.cardBackImage+"'>"+
										"<li><img data-original='"+data.cardBackImageZh+"' src='"+data.cardBackImageZh+"'  alt='图片'  style='width:100%;height:100%'/></li>"+
									 "</ul>"+
								   "</a>" 
		    		  }				 
		              form.render();//需要渲染一下
		           }  
		      }
  		    ]],
  		    done: function (res, curr, count) {
  		    	  permissionFUN()//功能按钮权限
  		    	 if(res.status!=200){
		    		if(res.status == 666){
		    			  TIMEOUT(); 
	  		        }else{
                	  $(".layui-none").text(res.resultMsg)
	  		        }  
                 }
  		    	 checkboxTable(res,"test2",pageDataIdMap,idMap,newidMap)
              }
  		  });
        })	
        //试题选择后确定按钮
         $('#formsure').on('click', function(){ 
        	 var returndata=batchSubmitWt(newidMap);//多选函数
        	 if(returndata.length == 0){
        		 layer.open({title:'提示',content:'请勾选用户'});
        	 }else if(returndata.length>0){
        		    var loadIndex2 = layer.load(1);// 显示加载层
	     			$.ajax({
	    				url:'/scmsUser/addBlackList.do',
	    				type:'POST',
	    				//async:false,
	    				data:formatParam(returndata),
	    				timeout: 200000,
	    				headers: setHeader(),
	    				success:function(res){         //请求成功
	    		        	   if(res.status == 200)
	    		  				{   
	    		        		   table.reload("tabledata", {});
	    		    			   newidMap={};
	    		    			   form.render();
    	    		  			}else if(res.status == 666){
    	    		  			    TIMEOUT(); 
    	    		  	        }else{
	    		  					layer.msg(res.resultMsg, {icon: res.icon});
	    		  				} 
	    		        	   layer.closeAll();//关闭加载层
	    	              }		
	    			}) 
        	 };
        	 
          });
		//监听行工具事件
        table.on('tool(auth-table)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {  //删除
                layer.confirm('真的要将此用户从黑名单中移除？', function (index) {
                	 var requestData = {"id": data.id, "other":data};
              	  	$.ajax({
          	           url: "/scmsUser/removeBlackList.do",               //请求地址
          	           type: "POST",              //请求类型
          	           data:formatParam(requestData),              //请求数据
          	           timeout: 200000,                //请求超时时间(毫秒)
          	           headers: setHeader(),
          	           success:function(res){         //请求成功
          	        	   if(res.status == 200)
          	  				{
          	    				layer.msg("黑名单移除成功！", {icon: res.icon},function(){
          	    					 layer.closeAll();//关闭加载层
          	    					table.reload("tabledata", {});
          						}); 					
          	  				}else if(res.status == 666){
          	  				    TIMEOUT();         	  		           
          	  		        }else{
          	  					layer.msg('黑名单用户移除失败', {icon: 5});
          	  				}
          	  				      
                        }
                     })
                    return false;
                });
            }
			form.render();//需要渲染一下	   
         });
       //黑名单搜索
	    form.on('submit(queryData)', function(data){
	        // 组装查询条件
	        var reqData = getConditionValue();
	        // 重新加载表格数据
	        table.reload("tabledata", {
	             where: {"reqData" : JSON.stringify(reqData)}
		        ,page: {
		            curr: 1 //重新从第 1 页开始
		          }
	        });
	    });
	    //添加和黑名单搜索
	    form.on('submit(queryData1)', function(data){
	        // 组装查询条件
	        var data={"condition":[{"field":"isBlackList","keyword":"0"},{"field":"name","keyword":$("#usernameTable").val()},{"field":"card","keyword":$("#usercard").val()}]}
	        // 重新加载表格数据
	        table.reload("scmsCompanyData", {
	             where: {"reqData" : JSON.stringify(data)}
		        ,page: {
		            curr: 1 //重新从第 1 页开始
		          }
	        });
	     });  
   }) 	
})
